package com.manage.service.impl;

import com.manage.dao.RoomDao;
import com.manage.dao.impl.RoomDaoImpl;
import com.manage.pojo.ResultData;
import com.manage.pojo.Room;
import com.manage.service.RoomService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomServiceImpl implements RoomService {
    @Override
    public ResultData selectByPage(String page, String limit) {
        //获取分页条件
        int j = Integer.parseInt(limit);
        int k = (Integer.parseInt(page)-1)*j;
        //处理数据库数据
        RoomDao roomDao=new RoomDaoImpl();
        List<Room> list=new ArrayList<>();

        try {
            List<Room> roomAll = roomDao.findAll();

            for (int i=k;i<((k+j)<roomAll.size()?(k+j):roomAll.size());i++){
                list.add(roomAll.get(i));
            }
//          返回结果
            return new ResultData(0,"查询成功",list,roomAll.size());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            return  new ResultData(10000,"数据异常");
        }

    }
}
